package com.mgvlife.ddlw.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.mgvlife.ddlw.formbean.StudentForm;
import com.mgvlife.ddlw.service.StudentService;
import com.mgvlife.ddlw.vo.Result;
import com.mgvlife.ddlw.vo.VoStudent;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xinhuo.util.JsonUtil;
import com.xinhuo.vo.JsonEasyUI;

@Controller("studentAction")
@Scope("prototype")
public class StudentAction extends ActionSupport implements
		ModelDriven<StudentForm> {

	private static final long serialVersionUID = -7081627550203304799L;
	private StudentForm dataForm = new StudentForm();
	@Resource
	private StudentService studentService = null;

	public void add() {
		Result result = null;
		try {
			result = studentService.studentAdd(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void update() {
		Result result = null;
		try {
			result = studentService.studentUpdate(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void list() {
		JsonEasyUI<VoStudent> result = null;
		try {
			result = studentService.getData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void delete() {
		Result result = null;
		try {
			result = studentService.studentDelete(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void signIn() {
		Result result = null;
		try {
			result = studentService.signIn(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}
	
	public void bindOpenId() {
		Result result = null;
		try {
			result = studentService.bindOpenId(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	@Override
	public StudentForm getModel() {
		return dataForm;
	}

}
